#include "stdafx.h"
#include "BIOS.h"
#include "SouthBridge/ICH.h"
#include "Register/GPR.h"

char const* DEADLINE = "20150630";

#ifdef NDEBUG
char const* LEGAL_BROKERID = "3040";
#else
char const* LEGAL_BROKERID = "3040";
#endif

void BIOS::LogOrderInsert(int rtn, Dealing const& dealing, int requestId)
{
	char const* direction = dealing.GetDirection() == Direction::SELL ? "S" : "B";

	string operation;
	switch (dealing.GetOperation())
	{
	case Operation::OPEN:
		operation = "OPEN";
		break;
	case Operation::OFFSET:
		operation = "OFFSET";
		break;
	case Operation::OFFSET_TODAY:
		operation = "OFFSET_TODAY";
		break;
	default:
		operation = "UNKNOWN";
		break;
	}

	string exchange;
	switch (dealing.GetExchange())
	{
	case Exchange::SHFE:
		exchange = "SHFE";
		break;
	case Exchange::DCE:
		exchange = "DCE";
		break;
	case Exchange::CZCE:
		exchange = "CZCE";
		break;
	case Exchange::CFFEX:
		exchange = "CFFEX";
		break;
	default:
		exchange = "CTP";
		break;
	}

	Log::Info(FT("LogOrderInsert: Rtn[%d] BusinessId[%d] ClientId[%s] Exchange[%s] RequestId[%d] LocalId[%d] Contract[%s] Flag[%s|%s] Price[%.2f,%d] Condition[%d]"
		,rtn,dealing.GetBusinessId(), dealing.GetClientId(), exchange.c_str(), requestId, dealing.GetLocalId()
		,dealing.GetContractCode(), direction, operation.c_str(), dealing.GetOrderPrice(), dealing.GetOrderQuantity(), dealing.GetOrderCondition()));
}

void BIOS::LogOrderAction(int rtn, OrderAction const& orderAction, int requestId)
{
	string exchange;
	switch (orderAction.GetExchange())
	{
	case Exchange::SHFE:
		exchange = "SHFE";
		break;
	case Exchange::DCE:
		exchange = "DCE";
		break;
	case Exchange::CZCE:
		exchange = "CZCE";
		break;
	case Exchange::CFFEX:
		exchange = "CFFEX";
		break;
	default:
		exchange = "CTP";
		break;
	}

	Log::Info(FT("LogOrderAction: Rtn[%d] BusinessId[%d] ClientId[%s] Exchange[%s] RequestId[%d] LocalId[%d] ActionId[%d] SystemId[%s]"
		,rtn,orderAction.GetBusinessId(), orderAction.GetClientId(), exchange.c_str()
		,requestId, orderAction.GetLocalId(), orderAction.GetActionId(), orderAction.GetSystemNo()));
}